package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Arrays;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sislm001;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Idcpe091Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Idcpe091Report {
	private String nomeClasse;
	private long jRegger;
	private String f1;
	private String f3;
	private String f2;
	private int dataCorrente;
	public String filia1;
	private String[] nomide = new String[3];
	private int[] datnas = new int[3];
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	DidCadastro vwDidcad = new DidCadastro();
	SicControle vwDvecon = new SicControle();
	SicCadastro criminalView = new SicCadastro();
	DidCadastro civilView = new DidCadastro();
	SicTabelas vwTabele = new SicTabelas();
	// Classes includes
	Estla001 estla001 = new Estla001();
	Sislm001 sislm001 = new Sislm001();

	public Idcpe091Report() throws JRException {
		inicializar();
	}

	public Idcpe091Report(Sessao sessao) throws JRException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		jRegger = 0;
		Arrays.fill(nomide, "");
		Arrays.fill(datnas, 0);
		dataCorrente = 0;
		report.setNumeroRel(1, "D");
		{
			report.setNumeroLinhaRel(3, 1);
			{
				report.adicionaCampo(50, 13, "Jregger", "N", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(20, 60, "Nomide[1]", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(10, 4);
			{
				report.adicionaCampo(3, 9, "lit_3_9", "C", "", "FILIACAO:");
				report.adicionaCampo(13, 60, "F1", "X", "", "");
				report.adicionaCampo(74, 3, "F3", "X", "", "");
				report.adicionaCampo(78, 60, "F2", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(11, 2);
			{
				report.adicionaCampo(3, 11, "lit_3_11", "C", "", "NASCIDO EM:");
				report.adicionaCampo(15, 8, "Datnas[1]", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(20, 1);
			{
				report.adicionaCampo(12, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
		}
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public long getJregger() {
		return jRegger;
	}

	public void setJregger(long jRegger) throws ParseException {
		this.jRegger = jRegger;
		report.adicionaValorReport("Jregger", jRegger);
	}

	public String getF1() {
		return f1;
	}

	public void setF1(String f1) throws ParseException {
		this.f1 = f1;
		report.adicionaValorReport("F1", f1);
	}

	public String getF3() {
		return f3;
	}

	public void setF3(String f3) throws ParseException {
		this.f3 = f3;
		report.adicionaValorReport("F3", f3);
	}

	public String getF2() {
		return f2;
	}

	public void setF2(String f2) throws ParseException {
		this.f2 = f2;
		report.adicionaValorReport("F2", f2);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String[] getNomide() {
		return nomide;
	}

	public void setNomide(String[] nomide) throws ParseException {
		this.nomide = nomide;
		report.adicionaValorReport("Nomide", nomide);
	}

	public int[] getDatnas() {
		return datnas;
	}

	public void setDatnas(int[] datnas) throws ParseException {
		this.datnas = datnas;
		report.adicionaValorReport("Datnas", datnas);
	}

	public String getNomide(int index) {
		return nomide[index];
	}

	public void setNomide(int index, String nomide) throws ParseException {
		this.nomide[index] = nomide;
		report.adicionaValorReport("Nomide" + "[" + String.valueOf(index) + "]", nomide);
	}

	public int getDatnas(int index) {
		return datnas[index];
	}

	public void setDatnas(int index, int datnas) throws ParseException {
		this.datnas[index] = datnas;
		report.adicionaValorReport("Datnas" + "[" + String.valueOf(index) + "]", datnas);
	} // /

	public String getFilia1() {
		return this.f1 + this.f2 + this.f3;
	}

	public void setFilia1(String filia1) throws ParseException {
		this.filia1 = filia1;
		this.f1 = UtilBean.subStr(filia1, 0, 60);
		report.adicionaValorReport("F1", UtilBean.subStr(filia1, 0, 60));
		this.f2 = UtilBean.subStr(filia1, 60, 60);
		report.adicionaValorReport("F2", UtilBean.subStr(filia1, 60, 60));
		this.f3 = UtilBean.subStr(filia1, 120, 3);
		report.adicionaValorReport("F3", UtilBean.subStr(filia1, 120, 3));
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}
}
